package com.jza04.flightbooking.mapper;

import com.jza04.flightbooking.entity.Passenger;
import org.apache.ibatis.annotations.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * 旅客Mapper接口
 */
@Mapper
public interface PassengerMapper {
    
    /**
     * 查询所有旅客
     */
    @Select("SELECT * FROM passenger_JZA04")
    List<Passenger> findAll();
    
    /**
     * 根据ID查询旅客
     */
    @Select("SELECT * FROM passenger_JZA04 WHERE passenger_id = #{passengerId}")
    Passenger findById(Integer passengerId);
    
    /**
     * 根据身份证号查询旅客
     */
    @Select("SELECT * FROM passenger_JZA04 WHERE id_card = #{idCard}")
    Passenger findByIdCard(String idCard);
    
    /**
     * 添加旅客
     */
    @Insert("INSERT INTO passenger_JZA04(name, id_card, phone, email, total_purchase, vip_discount) " +
            "VALUES(#{name}, #{idCard}, #{phone}, #{email}, #{totalPurchase}, #{vipDiscount})")
    @Options(useGeneratedKeys = true, keyProperty = "passengerId")
    int insert(Passenger passenger);
    
    /**
     * 更新旅客
     */
    @Update("UPDATE passenger_JZA04 SET name = #{name}, id_card = #{idCard}, phone = #{phone}, " +
            "email = #{email}, total_purchase = #{totalPurchase}, vip_discount = #{vipDiscount} " +
            "WHERE passenger_id = #{passengerId}")
    int update(Passenger passenger);
    
    /**
     * 删除旅客
     */
    @Delete("DELETE FROM passenger_JZA04 WHERE passenger_id = #{passengerId}")
    int delete(Integer passengerId);
    
    /**
     * 更新旅客购票总金额
     */
    @Update("UPDATE passenger_JZA04 SET total_purchase = total_purchase + #{amount} WHERE passenger_id = #{passengerId}")
    int updateTotalPurchase(Integer passengerId, BigDecimal amount);
    
    /**
     * 更新VIP折扣
     */
    @Update("UPDATE passenger_JZA04 SET vip_discount = #{vipDiscount} WHERE passenger_id = #{passengerId}")
    int updateVipDiscount(Integer passengerId, BigDecimal vipDiscount);
} 